#!/usr/bin/env python
# encoding: utf-8
'''
@author: Excelsiorly
@license: (C) Copyright 2022, All Rights Reserved.
@contact: excelsiorly@qq.com
@file: task3.py
@time: 2022/1/23 15:28
@desc:
'''


# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(H, X, Y):
    # write your code in Python 3.6
    res = []
    H.sort()
    n = len(H)

    def backtrack(idx, X, Y, count):
        if idx==n or ((X - H[idx] <= 0 and Y == 0) and (Y - H[idx] <= 0 and X==0)):
            res.append(count)
            return
        for i in range(idx, n):
            if X - H[i] >= 0:
                backtrack(i + 1, X - H[i], Y, count + 1)
            if Y - H[i] >= 0:
                backtrack(i + 1, X, Y - H[i], count + 1)
    backtrack(0, X, Y, 0)
    return max(res)

if __name__ == '__main__':
    H = [6, 5, 5, 4, 3]
    X = 8
    Y = 9
    res = solution(H, X, Y)
    print(res)